package com.sanbi.erp.core.util;

import com.sanbi.erp.core.system.Enums;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Generator {
    /**
     * @desc 创建对象编号，如采购计划编号
     * @author wanggang
     * @time 2022/7/13 16:50
     */
    public static String createObjectSn(Enums.ObjectType objectType){
        String prefix = objectType.getPrefix();
        String number = createNumber();
        return String.format("%s%s",prefix,number);
    }


    public static String createProductSku(Enums.ObjectType objectType){
        String prefix = objectType.getPrefix();
        String number = createNumberTwo();
        return String.format("%s%s",prefix,number);
    }


    private static String createNumber() {
        return DateTimeFormatter.ofPattern("yyMMddHHmmssSSS").format(LocalDateTime.now());
    }

    // 随机生成4位数
    private static String createNumberTwo() {
        Integer v = (int)(Math.random() * 9000 + 1000);
        return v.toString();
    }

    public static void main(String[] args) {
        int v = (int)(Math.random() * 9000 + 1000);
        Integer v2 = (int)(Math.random() * 9000 + 1000);
        System.out.println(v2.toString());
    }
}
